package com.mexcad.reports.utils;


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class ReportServlet extends HttpServlet{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws IOException, ServletException {

		String tipoDoc = request.getParameter("tipoReporte");
		


		//String path=request.getContextPath()+"/resources/imagenes/sectur.gif";
		String Imagepath=this.getServletContext().getRealPath("")+"/resources/imagenes/sectur.gif";

		int numColumnas=4;
		  
		 String []header =new String[numColumnas];
		 float []tamCols =new float[numColumnas];
		 for(int i=1;i<=numColumnas;++i){
			 header[i-1]="Header "+(i);
			 tamCols[i-1]=i+1;
		 }
	        
		 List<DataType []> listadoDatos = new ArrayList<DataType []>();
		 for(int i=0;i<500;++i){
			 
			 DataType []datos = new DataType[header.length];
			 for(int j=0;j<header.length;++j){
				 DataType b = new DataType();
				 if(j%2==0){
					 b.setDataType(DataType.CURRENCY_TYPE);
					 b.setData(new Double(i*200)/(i+1)*5);
					 b.setAlignMode(DataType.RIGHT);
				 }else{
					 b.setData("datoX_"+j+"_"+i);
					 b.setDataType(DataType.STRING_TYPE);
				 }
				
				 datos[j]=b;
				 
			 }
			 listadoDatos.add(datos);
		 }
	
		
		
		

		response.setContentType("application/pdf");
		
		
		
		PDFTable pdfTable;
		try {
			PDFSecturDocument doc= new PDFSecturDocument(response.getOutputStream(),"Encabezado","Subtitulo",Imagepath);
			pdfTable = new PDFTable(tamCols,header,listadoDatos);
			doc.addPdfTable(pdfTable);
			doc.closeDocument(); 
		} catch (PDFDocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
	}


}
